package cn.sinobest.pe.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * properties文件加载工具类
 * @author wuxinxue
 * @time 2015-6-10 上午8:57:48
 * @copyright hnisi
 */
public class PropertyHandlerUtil {
	
	private static PropertyHandlerUtil instance = null;
	
	private final Logger LOG = LoggerFactory.getLogger(getClass());
	
	/**
	 * 获取实例方法
	 */
	public static PropertyHandlerUtil getInstance() {
		if (instance == null) {
			instance = new PropertyHandlerUtil();
		}
		return instance;
	}
		
	/**
	 * 加载属性文件
	 * @param fileName 文件路径
	 * @return  属性Map
	 */
	public Properties loadProps(String fileName) {
		if (fileName != null && fileName.length()>0) {
			Properties properties = new Properties();
			try {
				InputStream inputStream = PropertyHandlerUtil.class.getResourceAsStream(fileName);
				properties.load(inputStream);
			} catch (IOException e) {
				LOG.error("load properties file occur exception:" + fileName, e);
				return null;
			}
			return properties;
		} else {
			LOG.info("the provided properties file name is null!");
			return null;
		}
	}
	
}
